<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
  import echarts from 'echarts'

  require('echarts/theme/macarons') // echarts theme
  import resize from './mixins/resize'
  import 'echarts/map/js/province/gansu.js'

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '300px',
      }
    },
    data() {
      return {
        chart: null
      }
    },
    watch: {
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
          title: {
            show: false,
          },
          toolbox: {
            show: false
          },
          visualMap: {
            show: false, //虽然不展示视觉映射组件，但是下面的某些配置是生效的
            // min: 100,
            // max: 700,
            // text: ["High", "Low"],
            realtime: false,
            // calculable: true,
            inRange: {
              color: ["rgb(0,137,121)"],
            },
          },
          series: [
            {
              type: "map",
              mapType: "甘肃", // 自定义扩展图表类型，必须和registerMap的第一个参数相同
              itemStyle:{
                normal:{
                  label:{show: true },
                  borderWidth:1, //省份的边框宽度
                  borderColor: '#f60' , //省份的边框颜色
                  color: '#ece2df',//地图背景颜色
                  areaStyle:{color:'#f60'}//设置地图颜色
                },
                emphasis:{label:{show: true }}
              },
              data: []
            },
          ],
        });
      }
    }
  }
</script>
